package ToYesterday.Day03;


class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
        next = null;
    }
}

public class Solution {

    public static void main(String[] args) {
        ListNode head=null;
        head = insertNode(head,1);
        System.out.println(head.val);
    }
    public static ListNode insertNode(ListNode head, int val) {
        // write your code here
        ListNode nodep = head;
        ListNode newVal = new ListNode(val);
        if (nodep ==null){
            head = newVal;
            return head;
        }else if (head.val<val){
            newVal.next = head;
            head = newVal;
            return head;
        }else {
            while (nodep.next!=null&&nodep.next.val<val){
                nodep=nodep.next;
            }
            newVal.next = nodep.next;
            nodep.next=newVal;
            return head;
        }
    }


    public ListNode findNode(ListNode head, int val) {
        // write your code here
        while (head!=null){
            if (val==head.val){
                return new ListNode(val);
            }
            head = head.next;
        }
        return null;
    }
}
